<template>
	<view class="work-container">
		<!-- 搜索框-->
		<uni-search-bar @confirm="handleQuery" v-model="queryParams.pigCode" placeholder="请输入耳号" bgColor="#F0F0F0">
		</uni-search-bar>
		<uni-group mode="card" v-for="(item, index) in pigList" :index="index" :key="index">
			<view class="code">
				<text style="font-size:18px">耳号：{{item.pigCode}}</text>
				<uni-icons class="icon" type="right" size="15" color="#000000"  @click="toDetials(item.pigId)" ></uni-icons>
			</view>
			<hr />
			<view class="message">
				<view v-if="item.pigBreed == 1"> 品种：{{$dict.selectDictLabel('hmy_pig_breed', 1)}} </view>
				<view v-else-if="item.pigBreed ==2"> 品种：{{$dict.selectDictLabel('hmy_pig_breed', 2)}} </view>
				<view v-else-if="item.pigBreed ==3"> 品种：{{$dict.selectDictLabel('hmy_pig_breed', 3)}} </view>
				<view v-else-if="item.pigBreed ==4"> 品种：{{$dict.selectDictLabel('hmy_pig_breed', 4)}} </view>
				
				<view v-if="item.pigType == 1"> 类型：{{$dict.selectDictLabel('hmy_pig_type', 1)}} </view>
				<view v-else-if="item.pigType ==2"> 类型：{{$dict.selectDictLabel('hmy_pig_type', 2)}} </view>
				<view v-else-if="item.pigType ==3"> 类型：{{$dict.selectDictLabel('hmy_pig_type', 3)}} </view>
				
				<view v-if="item.pigSex == 1"> 性别：{{$dict.selectDictLabel('hmy_pig_sex', 1)}} </view>
				<view v-else-if="item.pigSex ==2"> 性别：{{$dict.selectDictLabel('hmy_pig_sex', 2)}} </view>
				
				<view v-if="item.phouseType == 1"> 栏舍：{{$dict.selectDictLabel('hmy_park_type', 1)}} </view>
				<view v-else-if="item.phouseType ==2"> 栏舍：{{$dict.selectDictLabel('hmy_park_type', 2)}} </view>
				<view v-else-if="item.phouseType ==3"> 栏舍：{{$dict.selectDictLabel('hmy_park_type', 3)}} </view>

				<view> 出生日期：{{item.pigBirthday}}</view>
			</view>
		</uni-group>
		<!-- 加载更多 -->
		<uni-load-more iconType="auto" :status="status" />
		<!-- 新增加号悬浮 icon -->
		<uni-fab :pattern="pattern" :horizontal="horizontal" :vertical="vertical" @fabClick="fabClick" />
	</view>
</template>

<script>
	import {
		listPig
	} from "@/api/hmy/pig";

	export default {
		name: "Pig",
		data() {
			return {
				//猪只列表
				pigList: [],
				horizontal: 'right',
				vertical: 'bottom',
				pattern: {
					buttonColor: '#55aa7f',
				},
				//加载更多
				status: 'more',
				total: '',
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					type: undefined,
				}
			};
		},
		created() {
			this.getList();
		},
		//上拉加载
		onReachBottom() {
			this.queryParams.pageSize += 5;
			this.getList();
			if (this.pigList.length >= this.total) {
				this.status = 'noMore';
			} else {
				this.status = 'loading';
			}
		},
		methods: {
			/** 查询猪只档案列表 */
			getList() {
				uni.showLoading({
					title:"加载中"
				})
				listPig(this.queryParams).then(response => {
					this.pigList = response.rows;
					this.total = response.total;
					uni.hideLoading();
				});
			},
			// 新增猪只档案记录
			fabClick() {
				this.$tab.navigateTo('/pages/hmy/pig/pigAdd');
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},

			//详情
			toDetials(e) {
				console.log("xiangqing", e)
				this.$tab.navigateTo('/pages/hmy/pig/pigDetials?id=' + e);
			}
		}
	};
</script>
<style lang="scss">
	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		min-height: 100%;
		height: auto;
		background-color: #fcfcfc;
	}

	view {
		font-size: 16px;
		line-height: inherit;
	}

	/* #endif */
	.code {
		margin-bottom: 5px;
	}

	.icon {
		float: right;
		margin-right: 10px;
		margin-top: 5px;
	}

	.message {
		margin-top: 5px;
		color: #989897;
		line-height: 25px;
	}
</style>